package org.learn.java.mq.consumer;

import java.util.Properties;

import javax.sound.midi.Receiver;

import org.learn.java.mq.MqContent;
import org.learn.java.mq.listener.MyMessgeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.PropertyValueConst;

public class ConsumerTest {

	public static Logger logger = LoggerFactory.getLogger(ConsumerTest.class);
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		generalreceive();	//普通消息接受
	}

	public static void generalreceive() {
		logger.debug("----ConsumerTest.generalreceive----");
		// 配置producer参数
		Properties properties = new Properties();
		properties.put(PropertyKeyConst.ConsumerId, "CID_t_1");
		properties.put(PropertyKeyConst.AccessKey, MqContent.MQ_AccessKey );
		properties.put(PropertyKeyConst.SecretKey, MqContent.MQ_SecretKey);
		/*properties.put(PropertyKeyConst.MessageModel,
				PropertyValueConst.BROADCASTING);*/
		Consumer consumer = ONSFactory.createConsumer(properties);
		
		MessageListener listener = new MyMessgeListener();
		
		consumer.subscribe("Topic_t_1", "m1", listener);
		
		consumer.start();
		logger.debug("consumer启动成功");
		
	}
}
